import { isEmptyObject } from "../../utils";

export class PickInfoRule {
  constructor(required, isHideSelfPickerInfo) {
    this.required = required;
    this.asyncValidator = (rule, pickInfo) => {
      if (!required) return Promise.resolve();

      if (isEmptyObject(pickInfo?.site)) {
        return Promise.reject("请选择自提点");
      }

      // 提货人白名单
      if (isHideSelfPickerInfo == 1 || isHideSelfPickerInfo == 2) {
        return Promise.resolve();
      }

      if (isEmptyObject(pickInfo?.picker) || pickInfo?.picker?.id === 0) {
        return Promise.reject("请填写提货人");
      }
      return Promise.resolve();
    };
  }
}
